<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">    
<html xmlns="http://www.w3.org/1999/xhtml">   
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <%@ include file="/WEB-INF/pages/common/meta.jsp" %>
    <%@ include file="/WEB-INF/pages/common/common.jsp" %>
    <script type="text/javascript" src="${ctx}/static/js/main.js?time=New Date()"></script>
    <script type="text/javascript" src="${ctx}/static/js/workflow/workflowCommon.js?time=New Date()"></script>
    <script type="text/javascript" src="${ctx}/static/js/expand/easyui-validatebox.expandMethod.js"></script>
    <title>月度返款明细查询</title>
    <style type="text/css">
    	.td_center {
    		text-align:center;
    	}
    </style>
</head>

<body class="easyui-layout">
	<script type="text/javascript">
	//获取当前登录机构类型
	var cmsOrgType = decodeURI('${sessionScope.CURRENT_USER.cmsOrgType}');
	//获取当前登录机构编号
	var cmsBaseOrgCode = decodeURI('${sessionScope.CURRENT_USER.cmsBaseOrgCode}');
	var cmsOrgProperty;

	$(function() {
		var columns=[[
			  			/*{field:'id',title:'文件编号',align: 'center'},*/
			  			{field:'handleBranchName',title: '组织名称',align:'center',width: 80},
			  			{field:'completePoll',title:'结案票数',align: 'center',width :200,formatter:returnItem},
			  			{field:'pushInsurancePoll',title:'推送保险票数',align: 'center',width : 80,formatter:pushInsurancePoll},
			  			{field:'pushInsuranceMoney',title:'推送保险金额',align: 'center',width : 80},
			  			{field:'signInsuranceNoCompensationPoll',title:'签收件保险不赔票数',align: 'center',formatter:signInsuranceNoCompensationPoll},
			  			{field:'signInsuranceNoCompensationMoney',title:'签收件保险不赔金额',align: 'center'},
			  			{field:'breakageWithoutInsurancePoll',title:'破损件不走保险票数',align: 'center',formatter:breakageWithoutInsurancePoll},
			  			{field:'breakageWithoutInsuranceMoney',title:'破损件不走保险金额',align: 'center',width :150},
			  			{field:'unqualifiedValueCertificatePoll',title:'价值证明不合格票数',align: 'center',width :150,formatter:unqualifiedValueCertificatePoll},
			  			{field:'arbitrationWithoutAcceptPoll',title:'仲裁不受理票数',align: 'center',width :150,formatter:arbitrationWithoutAcceptPoll},
			  			{field:'acceptExternalPackagePoll',title:'只受理外包装票数',align: 'center',width :150,formatter:acceptExternalPackagePoll},
			  			{field:'overdueInsurancePoll',title:'保险逾期票数',align: 'center',width :150,formatter:overdueInsurancePoll},
			  			{field:'separateRiskPurchaseOfflineProcess',title:'单独购险件线下处理票数',align: 'center',width :150,formatter:separateRiskPurchaseOfflineProcess}
	  		   ]]; 
		newloadGrid("exportInfoType", columns,{
				url : "",
		    	pageSize:50,
	    	    toolbar:"#exportType",
	    	    singleSelect : 'false',
	    	    pagination : 'true',
				fitColumns : true
 			});
	    $('#orgType').uceCombobox({
	        width: 150,
	        editable: false,
	        data: [
	            {'value':'20','text':'财务中心'},
	            {'value':'30','text':'网点',"selected" : true}]
	    });
	    queryOrgType();
    	//开始时间，结束时间赋默认值
    	setDatetimebox();
        initQueryBeginTime();
        //初始化事件时间
        initQueryEndTime();
	});
	
	function queryOrgType(){
		$.ajax({
	        // 请求方式
	        type:"post",
	        // 发送请求地址
	        url:G_CTX_PATH + '/cs/csDisposeSurveyController/queryOrgType.do',
	        // 设置返回数据的格式
	        dataType:"json",
	        // 请求成功后的回调函数 data为json格式
	        success:function(data){
	        	if (data.success == true) {
	        		if(data.orgType == 30){
	        		    $('#codeName').textbox('readonly', true);
	        		    $('#orgType').textbox('readonly', true);
	        		}
	        	}
	        }
	    });
	}
	
	function returnItem(value,row){
		if(value == null){
        	return null;
	    }
	    return '<a style="color: #0000FF;" onclick="openLookOrderDetail(\''+row.handleBranchCode+'\', \''+ 1 +'\')" href="javascript:void(0)">'+value+'</a>';
	}
	function pushInsurancePoll(value,row){
		if(value == null){
        	return null;
	    }
	    return '<a style="color: #0000FF;" onclick="openLookOrderDetail(\''+row.handleBranchCode+'\', \''+ 2 +'\')" href="javascript:void(0)">'+value+'</a>';
	}
	function signInsuranceNoCompensationPoll(value,row){
		if(value == null){
        	return null;
	    }
	    return '<a style="color: #0000FF;" onclick="openLookOrderDetail(\''+row.handleBranchCode+'\', \''+ 3 +'\')" href="javascript:void(0)">'+value+'</a>';
	}
	function breakageWithoutInsurancePoll(value,row){
		if(value == null){
        	return null;
	    }
	    return '<a style="color: #0000FF;" onclick="openLookOrderDetail(\''+row.handleBranchCode+'\', \''+ 4 +'\')" href="javascript:void(0)">'+value+'</a>';
	}
	function unqualifiedValueCertificatePoll(value,row){
		if(value == null){
        	return null;
	    }
	    return '<a style="color: #0000FF;" onclick="openLookOrderDetail(\''+row.handleBranchCode+'\', \''+ 5 +'\')" href="javascript:void(0)">'+value+'</a>';
	}
	function arbitrationWithoutAcceptPoll(value,row){
		if(value == null){
        	return null;
	    }
	    return '<a style="color: #0000FF;" onclick="openLookOrderDetail(\''+row.handleBranchCode+'\', \''+ 6 +'\')" href="javascript:void(0)">'+value+'</a>';
	}
	function acceptExternalPackagePoll(value,row){
		if(value == null){
        	return null;
	    }
	    return '<a style="color: #0000FF;" onclick="openLookOrderDetail(\''+row.handleBranchCode+'\', \''+ 7 +'\')" href="javascript:void(0)">'+value+'</a>';
	}
	function overdueInsurancePoll(value,row){
		if(value == null){
        	return null;
	    }
	    return '<a style="color: #0000FF;" onclick="openLookOrderDetail(\''+row.handleBranchCode+'\', \''+ 8 +'\')" href="javascript:void(0)">'+value+'</a>';
	}
	function separateRiskPurchaseOfflineProcess(value,row){
		if(value == null){
        	return null;
	    }
	    return '<a style="color: #0000FF;" onclick="openLookOrderDetail(\''+row.handleBranchCode+'\', \''+ 9 +'\')" href="javascript:void(0)">'+value+'</a>';
	}
	
	// 初始化查询的开始时间
	function initQueryBeginTime(){
	    var date = new Date();
	    var year = date.getFullYear();
	    var month = date.getMonth() + 1;
	    var date = date.getDate()-1;
//	    var beginTime = year + "-" + month +"-"+ date ;
//	    $('#startTime').datetimebox('setValue', beginTime);
	    var beginTime = year + "-" + month +"-"+ date;
//	    var begin = Date.parse(beginTime);
	    $("#startTime").datebox('setValue',beginTime);
	}
	// 初始化查询的结束时间
	function initQueryEndTime(){
	    var date = new Date();
	    var year = date.getFullYear();
	    var month = date.getMonth() + 1;
	    var date = date.getDate()-1;
//	    var endTime = year + "-" + month +"-"+ date ;
//	    $('#endTime').datetimebox('setValue', endTime);
	    var endTime = year + "-" + month +"-"+ date;
//	    var end = Date.parse(endTime);
	    $("#endTime").datebox('setValue',endTime);
	}
	
	function openLookOrderDetail(handleBranchCode,type){
	    openDialog("dlgSecondary", '保险工单明细查看');
	    //查询前先清空grid
	    $("#dgSecondary").datagrid("loadData",{"total":0,"rows":[]});
	    var orgTypeD = orgType;
	    if(type == '10'){
	        orgType = type;
	    }
	    var startTime = $('#startTime').datetimebox('getValue');
	    var endTime = $('#endTime').datetimebox('getValue');
	    var productDataGridParams = {
	        url: G_CTX_PATH + '/cs/csInsuranceCompensate/findOrderDetail.do',
	        pageSize: 50,
	        queryParams:{'handleBranchCode':handleBranchCode,'startTimeD':startTime,'endTimeD':endTime,'type':type},
	        // toolbar : '#dlgSecondary',
	        pagePosition:'top',
	        rownumbers:'true',
	        singleSelect: 'true',
	        fitColumns: 'true',
	        collapsible : 'true',
	        pagination: 'true'
	    };
	    newloadGrid('dgSecondary', orderDetailColumns, productDataGridParams);
	    $('#type').textbox('setValue',type);
	    $('#handleBranchCode').textbox('setValue',handleBranchCode);
	    $('#startTimeD').datebox('setValue', startTime);
	    $('#endTimeD').datebox('setValue', endTime);
	}
	var orderDetailColumns = [[
	{field:'code',title:'保险工单编码',align:'center',width:100,sortable:false,formatter: formatTip} ,
        {field:'acoCode',title:'仲裁投诉编码',align:'center',width:100,sortable:false,formatter: formatTip} ,
        {field:'aaoCode',title:'仲裁申诉编码',align:'center',width:100,sortable:false,formatter: formatTip} ,
        {field:'waybillNum',title:'运单编码',align:'center',width:100,sortable:false,formatter: formatTip} ,
        {field:'orderStatusStr',title:'工单状态',align:'center',width:100,sortable:false},
        {field:'auditStatusStr',title:'工单审核结果',align:'center',width:100,sortable:false},
        {field:'cpicAuditStatusStr',title:'保险审核结果',align:'center',width:100,sortable:false},
        {field:'proofAuditStatusStr',title:'赔付凭证审核结果',align:'center',width:100,sortable:false},
        {field:'compensateMoney',title:'优速申保金额',align:'center',width:130,sortable:false,formatter: formatTip} ,
        {field:'websiteMoney',title:'赔付网点金额',align:'center',width:130,sortable:false,formatter: formatTip} ,
        {field:'totalMoney',title:'保险赔付金额',align:'center',width:130,sortable:false,formatter: formatTip} ,
        {field:'beComplainantBranchName',title:'被投诉网点',align: 'center',width:100, formatter : formatTip},
        {field:'beComplainantCenterName',title: '被投诉方财务中心',align:'center', width: 100, formatter: formatTip},
        {field:'beComplainantName',title: '被投诉人',align:'center', width: 100, formatter: formatTip},
        {field:'complainTypeStr',title: '投诉类型',align:'center', width: 100},
        {field:'claimTime',title: '投诉时间',align:'center', width: 130, formatter:function (value) {
            return formatData(value)
        }},
        {field:'complainantBranchName',title:'投诉网点',align: 'center',width:100, formatter : formatTip},
        {field:'complainantCenterName',title: '投诉方财务中心',align:'center', width: 100, formatter: formatTip},
        {field:'complainantName',title: '投诉人',align:'center', width: 100, formatter: formatTip},
        {field:'createTime',title: '创建时间',align:'center', width: 130, formatter:function (value) {
            return formatData(value)
        }},
        {field:'updateTime',title: '最后处理时间',align:'center', width: 130, formatter:function (value) {
            return formatData(value)
        }},
        {field:'webSitePushFailReason',title: '推送网点失败原因',align:'center', width: 150, formatter: formatTip}
	]];
	
	//格式化日期
	function timeformatter(date) {
	    //获取年份
	    var y = date.getFullYear();
	    //获取月份
	    var m = date.getMonth() + 1;
	    return y + '-' + m;
	}
	
	//导出
	function doExport() {
	    //44554
	    var rows = $('#exportInfoType').datagrid('getRows');
	    if(rows.length>0){
	        confirmMsg("您确定要导出数据吗?", function(){
	            var data =serializeFormObj("formFindexportInfoType");
	            uceAjax(G_CTX_PATH + "/cs/csInsuranceReport/export.do", data, function (result) {
	            	 if (result.success == true) {
	            		 openTabCrossDomainIcsSimple("exportFileController_forward","数据导出查看","/cs/exportFileController/forward.do",true,0,portal_global_systemCode,false);
			            }else if(result.success == false){
			                showInfoMsg(result.msg);
			                 return;
			            }
	            }, "POST");
	        });
	    }else{
	        showInfoMsg("没有可导出的数据!");
	    }
	}
	
	//导出
	function doExportD() {
	    //44554
	    var rows = $('#dgSecondary').datagrid('getRows');
	    if(rows.length>0){
	        confirmMsg("您确定要导出数据吗?", function(){
	            var data =serializeFormObj("formFindProblemOrderD");
	            uceAjax(G_CTX_PATH + "/cs/csInsuranceCompensate/doExportD.do", data, function (result) {
	            	 if (result.success == true) {
	            		 openTabCrossDomainIcsSimple("exportFileController_forward","数据导出查看","/cs/exportFileController/forward.do",true,0,portal_global_systemCode,false);
			            }else if(result.success == false){
			                showInfoMsg(result.msg);
			                 return;
			            }
	            }, "POST");
	        });
	    }else{
	        showInfoMsg("没有可导出的数据!");
	    }
	}
	
	function findOrderIndex(){
        var beginTime = $('#startTime').datetimebox('getValue');
        var endTime = $('#endTime').datetimebox('getValue');
        var datecha = datedifference(beginTime,endTime);
        if(datecha > 31){
            showInfoMsg('查询时间不能相差32天！');
            return;
        }
        //点击按钮加载URL
        var opts = $("#exportInfoType").datagrid("options");
        opts.url = "../csInsuranceReport/findInsuranceReport.do";
        
        var isValid = $('#formFindexportInfoType').form('validate');
        if(isValid){
            $("#exportInfoType").datagrid("load", serializeFormObj("formFindexportInfoType"));
        }
	}
	
	    /** 判断2个日期相差天数 */
    function datedifference(sDate1, sDate2) {
        var dateSpan,
            tempDate,
            iDays;
        sDate1 = Date.parse(sDate1);
        sDate2 = Date.parse(sDate2);
        dateSpan = sDate2 - sDate1;
        dateSpan = Math.abs(dateSpan);
        iDays = Math.floor(dateSpan / (24 * 3600 * 1000));
        return iDays
    }
	
	function resetQuery(){
		 $("#formFindexportInfoType").form('reset');
		    $('#orgType').uceCombobox({
		        width: 150,
		        editable: false,
		        data: [
		            {'value':'20','text':'财务中心'},
		            {'value':'30','text':'网点',"selected" : true}]
		    });
	    	//开始时间，结束时间赋默认值
	    	setDatetimebox();
	        initQueryBeginTime();
	        //初始化事件时间
	        initQueryEndTime();
	}

	function myformatter(value){
		var date = new Date(value);
		var y = date.getFullYear();
		var m = date.getMonth()+1;
		var d = date.getDate();
		return y+"/"+m;
	}
	function findMonthlyRefund() {
//      var beginTime = $('#createTimeBegin').datetimebox('getValue');
//      var endTime = $('#createTimeEnd').datetimebox('getValue');
//      var datecha = datedifference(beginTime,endTime);
//      if(datecha > 31){
//          showInfoMsg('查询时间不能相差32天！');
//          return;
//      }
        //点击按钮加载URL
        var opts = $("#exportInfoType").datagrid("options");
        opts.url = "../CsMonthlyRefund/findMonthlyRefund.do";
        
        var isValid = $('#formFindexportInfoType').form('validate');
        if(isValid){
            $("#exportInfoType").datagrid("load", serializeFormObj("formFindexportInfoType"));
        }
    }
	/**
	 * 开始时间，结束时间 赋默认值
	 */
	function setDatetimebox(){
		var myDate = new Date();
		var year = myDate.getFullYear();
		var month = myDate.getMonth()+1;
		var date = myDate.getDate();
		var beginDate = year +"-"+ month +"-"+ date ;
		var begin = Date.parse(beginDate);
		$("#cutPaymentYears").datetimebox('setValue',formatTime(new Date(begin)));
	}

</script>
    <div id="exportType" style="padding:5px;">
		<form action="#" id="formFindexportInfoType">
        <div id="aa" class="easyui-accordion">
            <div title="" data-options="selected:true">
                <table style="width:auto">
                    <tr>
                        <td align="right">机构类型:</td>
                        <td><input name="orgType" id="orgType"  class="easyui-combobox"  data-options="validType:'Standard'"/></td>
                        <td align="right">组织名称:</td>
                        <td><input class="easyui-textbox"  labelPosition="left" labelWidth="100px" id = "codeName" name="codeName"></td>
                        <td align="right">起始时间:</td>
                        <td><input class="easyui-datebox" labelPosition="left" labelWidth="100px" id="startTime" name="startTime" data-options="prompt:'请输入查询开始时间',validType:'equaldDate[\'#startTime\']'" ></td>
                        <td align="right">截止时间:</td>
                        <td><input class="easyui-datebox" labelPosition="left" labelWidth="100px" id="endTime" name="endTime" data-options="prompt:'请输入查询截止时间',validType:'equaldDate[\'#endTime\']'" ><td>
                        <td>
                            <a href="#" class="easyui-linkbutton search" onclick="findOrderIndex()">查询</a>
	                        <a href="#" class="easyui-linkbutton reset" onclick="resetQuery()">重置</a>
	                        <a href="#" class="easyui-linkbutton search" onclick="doExport()">导出</a>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
	    </form>
	</div>
	
	<table id="exportInfoType" data-options="fit:true"></table>
	<!--
    	时间：2019-03-20
    	描述：弹出明细界面
    -->
	<div id="dlgSecondary" class="easyui-dialog"
     style="width: 1400px; height: 650px; padding: 20px 20px" closed="true">
    <form action="#" id="formFindProblemOrderD">
        <input id="queryType" type="hidden"/>
        <div id="aa" class="easyui-accordion">
            <div title="" data-options="selected:true">
                 <table style="width:auto">
                    <tr>
                    <td input name="handleBranchCode" id="handleBranchCode" class="easyui-textbox" ></td>
                    <td input id="startTimeD" name="startTimeD" class="easyui-datebox" ></td>
                    <td input class="easyui-datebox" id="endTimeD" name="endTimeD" ></td>
                    <td input class="easyui-textbox"  id="type" name="type" ></td>
                    <div style="margin-left: 38px">
                        <a href="#" class="easyui-linkbutton search" onclick="doExportD()">导出</a>
                    </div>
                </tr>
                </table>
            </div>
        </div>
    </form>
    <div style="width: 6000px; height: 550px; padding: 20px 20px">
        <table id="dgSecondary" class="easyui-datagrid" data-options="fit:true"></table>
    </div>
</div>
</body>
</html>